<template>
  <router-view></router-view>
</template>

<script setup>
import { onMounted, onUnmounted } from 'vue';
import tokenManager from '@/utils/tokenManager';

onMounted(async () => {
  const storedToken = localStorage.getItem('token');
  const storedUserInfo = localStorage.getItem('userInfo');
  
  // 只有当 token 和用户信息都存在时才尝试刷新
  if (storedToken && storedUserInfo) {
    console.log('[App] 检测到已存在登录状态，尝试刷新 token');
    await tokenManager.checkAndRefreshToken();
  }
});

onUnmounted(() => {
  tokenManager.stopRefreshTimer();
});
</script>

<style scoped>
</style>
